﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
using Utility;
namespace Service
{
    /// <summary>
    /// 功能：HW_ItemResult类数据访问
    /// 创建人：Wilson
    /// 创建时间：2013-1-30   
    /// </summary>
    public class HW_ItemResultService : IDisposable
    {
        #region 公共
        private System.ComponentModel.Component component = new System.ComponentModel.Component();

        private bool disposed = false;

        ~HW_ItemResultService()
        {
            Dispose(false);
        }

        #endregion

        #region IDisposable 成员

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!this.disposed)
            {

                if (disposing)
                {

                    component.Dispose();
                }

                disposed = true;

            }
        }
        #endregion
		#region##MapperHW_ItemResult
        public IList<HW_ItemResult> MapperList(SqlDataReader reader)
         {
            IList<HW_ItemResult> list = new List<HW_ItemResult>();
            HW_ItemResult obj=null;
            while (reader.Read())
            {
                obj = new HW_ItemResult();
                obj.XMBH = (int)reader["XMBH"];
                obj.Item = (int)reader["Item"];
                obj.Result = reader["Result"] as string;
                obj.EngLishItem = reader["EngLishItem"] as string;
                obj.ChineseItem = reader["ChineseItem"] as string;
                obj.Version = (int)reader["Version"];
                list.Add(obj);
            }
            return list;
         }
        public HW_ItemResult Mapper(SqlDataReader reader)
         {
            HW_ItemResult obj=null;
            if (reader.Read())
            {
                obj = new HW_ItemResult();
                obj.XMBH = (int)reader["XMBH"];
                obj.Item = (int)reader["Item"];
                obj.Result = reader["Result"] as string;
                obj.EngLishItem = reader["EngLishItem"] as string;
                obj.ChineseItem = reader["ChineseItem"] as string;
                obj.Version = (int)reader["Version"];
            }
            return obj;
         }
        #endregion
        #region##通过主键ID得到HW_ItemResult
        /// <summary>
        /// 功能：通过ID得到HW_ItemResult
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
        public HW_ItemResult GetById(int xmbh)
        {            
            string sql = "select * from HW_ItemResult where XMBH = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",4)
            };
            
            SqlDataReader reader=SqlHelper.ExecuteReader(WebConn.connString,CommandType.Text,sql,sp);
            return Mapper(reader);
        }
        #endregion
		
		#region##通过主键ID删除HW_ItemResult
        /// <summary>
        /// 功能：通过主键ID删除HW_ItemResult
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(int xmbh)
		{
			int i = 0;
			string sql = "delete from HW_ItemResult where XMBH = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",4)
            };
            i= SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
			return i;
		}
        /// <summary>
        /// 功能：通过主键ID删除HW_ItemResult
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(SqlTransaction transaction,int xmbh)
		{
			int i = 0;
			string sql = "delete from HW_ItemResult where XMBH = @PK";
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@PK",4)
            };
            i= SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
			return i;
		}
		#endregion			
		
        #region##添加HW_ItemResult
        /// <summary>
        /// 功能：添加HW_ItemResult
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(HW_ItemResult hw_itemresult)
        {
            int result = 0;
            string sql = "insert into HW_ItemResult(XMBH,Item,Result,EngLishItem,ChineseItem,Version) values(@XMBH,@Item,@Result,@EngLishItem,@ChineseItem,@Version)";			
            SqlParameter[] sp = new SqlParameter[]
            {
				new SqlParameter("@XMBH",hw_itemresult.XMBH),
				new SqlParameter("@Item",hw_itemresult.Item),
				new SqlParameter("@Result",hw_itemresult.Result),
				new SqlParameter("@EngLishItem",hw_itemresult.EngLishItem),
				new SqlParameter("@ChineseItem",hw_itemresult.ChineseItem),
				new SqlParameter("@Version",hw_itemresult.Version)
            };
            result = SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
            return result;
        }
         /// <summary>
        /// 功能：添加HW_ItemResult
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(SqlTransaction transaction,HW_ItemResult hw_itemresult)
        {
            int result = 0;
            string sql = "insert into HW_ItemResult(XMBH,Item,Result,EngLishItem,ChineseItem,Version) values(@XMBH,@Item,@Result,@EngLishItem,@ChineseItem,@Version)";			
            SqlParameter[] sp = new SqlParameter[]
            {
				new SqlParameter("@XMBH",hw_itemresult.XMBH),
				new SqlParameter("@Item",hw_itemresult.Item),
				new SqlParameter("@Result",hw_itemresult.Result),
				new SqlParameter("@EngLishItem",hw_itemresult.EngLishItem),
				new SqlParameter("@ChineseItem",hw_itemresult.ChineseItem),
				new SqlParameter("@Version",hw_itemresult.Version)
            };
            result = SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
            return result;
        }
        #endregion
		
		#region##得到HW_ItemResult集合
		/// <summary>
        /// 功能：得到HW_ItemResult集合
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>       
        /// <returns></returns>
		public IList<HW_ItemResult> GetList()
		{
			string sql = "select * from HW_ItemResult";			
			SqlDataReader reader = SqlHelper.ExecuteReader(WebConn.connString,CommandType.Text,sql);
            return MapperList(reader);
		}
		#endregion
		
		#region##修改HW_ItemResult
        /// <summary>
        /// 功能：修改HW_ItemResult
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModHW_ItemResult(HW_ItemResult hw_itemresult)
        {
            int result = 0;
            string sql = "update HW_ItemResult set XMBH = @XMBH,Item = @Item,Result = @Result,EngLishItem = @EngLishItem,ChineseItem = @ChineseItem,Version = @Version where XMBH = @XMBH";
            SqlParameter[] sp = new SqlParameter[]
            {       
				new SqlParameter("@XMBH",hw_itemresult.XMBH),
				new SqlParameter("@Item",hw_itemresult.Item),
				new SqlParameter("@Result",hw_itemresult.Result),
				new SqlParameter("@EngLishItem",hw_itemresult.EngLishItem),
				new SqlParameter("@ChineseItem",hw_itemresult.ChineseItem),
				new SqlParameter("@Version",hw_itemresult.Version)
            };
            result = SqlHelper.ExecuteNonQuery(WebConn.connString,CommandType.Text,sql,sp);
            return result;
        }
         /// <summary>
        /// 功能：修改HW_ItemResult
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModHW_ItemResult(SqlTransaction transaction,HW_ItemResult hw_itemresult)
        {
            int result = 0;
            string sql = "update HW_ItemResult set XMBH = @XMBH,Item = @Item,Result = @Result,EngLishItem = @EngLishItem,ChineseItem = @ChineseItem,Version = @Version where XMBH = @XMBH";
            SqlParameter[] sp = new SqlParameter[]
            {       
				new SqlParameter("@XMBH",hw_itemresult.XMBH),
				new SqlParameter("@Item",hw_itemresult.Item),
				new SqlParameter("@Result",hw_itemresult.Result),
				new SqlParameter("@EngLishItem",hw_itemresult.EngLishItem),
				new SqlParameter("@ChineseItem",hw_itemresult.ChineseItem),
				new SqlParameter("@Version",hw_itemresult.Version)
            };
            result = SqlHelper.ExecuteNonQuery(transaction,CommandType.Text,sql,sp);
            return result;
        }
        #endregion
		
		#region##统计HW_ItemResult
		/// <summary>
        /// 修改HW_ItemResult
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
		public int SelectCount()
		{
			int i = 0;
            string sql = "select count(*) from HW_ItemResult";
            i = (int)SqlHelper.ExecuteScalar(WebConn.connString,CommandType.Text,sql);
            return i;
		}
		/// <summary>
        /// 修改HW_ItemResult
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-30
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int SelectCountById()
        {
            int i=0;
            string sql="select count(XMBH) from HW_ItemResult";
            i = (int)SqlHelper.ExecuteScalar(WebConn.connString,CommandType.Text,sql);
            return i;
        }
		#endregion
        #region##自定义HW_ItemResult
        #endregion
                
    }
}
